package ru.jkff.jalgebra.monoid;

/**
 * User: jkff
 * Date: Aug 23, 2009
 * Time: 12:45:15 PM
 */
public abstract class MonoidUtils {
    private MonoidUtils() {}
    
    public static <T> T fold(Monoid<T> m, Iterable<T> ts) {
        return foldFrom(m, ts, m.unit());
    }

    public static <T> T foldFrom(Monoid<T> m, Iterable<T> ts, T seed) {
        for(T t : ts) seed = m.combine(seed, t);
        return seed;
    }
}
